package com.chai.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.chai.dao.MemberDao;
import com.chai.service.MemberService;
import com.chai.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDao memberDao;

    @Override
    public List<Integer> findMemberCountByMonths(List<String> months) {
        List<Integer> list = new ArrayList<>();
        for (String month : months) {
            String dateStr = month + "-" + DateUtils.getLastDayOfMonth(month);

            Integer count = memberDao.findMemberByMonth(dateStr);
            list.add(count);
        }
        return list;
    }
}
